<?php
/**
 * Session 
 * This class manages application session
 * 
 * @package    Lazy Framework
 * @subpackage session
 * @author     Eduardo Marcolino <eduardo.marcolino@gmail.com>
 * @copyright  (c) 2010 Eduardo Marcolino <eduardo.marcolino@gmail.com>
 */
class Session
{
	private $session;
	protected static $instance = null;
	
	/**
	 * Return the current instance of session
	 * @return Session instance
	 */
	public static function getInstance()
	{
		if (!isset(self::$instance))
 	    {
	      $class = __CLASS__;
 	      self::$instance = new $class();
 	      self::$instance->initialize();
 	    }
 	
 	    return self::$instance;
 	}
	
 	protected function initialize()
 	{
 		$this->session = $_SESSION;
 		$this->session['flash'] = array();
 	}

	public function getAttribute($key,$default = '')
	{
		return 	self::hasAttribute($key) ?  $this->session[$key] : $default;
	}
	
	public function hasAttribute($key)
	{
		return array_key_exists($key,$this->session);	
	}
	
	public function setAttribute($key,$value)
	{
		 $this->session[$key] = $value;
	}
	
	public function removeAttribute($key)
	{
		if (self::hasAttribute($key)) 
		{
			unset($this->session[$key]);
		}
	}
	
	public function getAttributeNames()
	{
		return array_keys($this->session);	
	}
	
	public function setFlash($key,$value)
	{
		 $this->session['flash'][$key] = $value;
	}
	public function getFlash($key)
	{
		 return $this->session['flash'][$key];
	}
	public function getFlashMessages()
	{
		return $this->session['flash'];
	}
}
?>